package cn.heyige.backend.algorithm;

import com.tyme.lunar.LunarHour;
import com.tyme.lunar.LunarYear;
import com.tyme.solar.SolarDay;
import com.tyme.solar.SolarTime;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

@Slf4j
public class LunarCalculator {

    public static LunarDate getPlumNumber(LocalDateTime now) {
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();

        SolarDay solarDay = SolarDay.fromYmd(year, month, day);
        SolarTime solarTime = SolarTime.fromYmdHms(year, month, day, hour, minute, second);
        LunarHour lunarHourDay = solarTime.getLunarHour();

        int lunarYear = LunarYear.fromYear(year).getSixtyCycle().getEarthBranch().getIndex() + 1;
        int lunarMonth = lunarHourDay.getLunarDay().getMonth();
        int lunarDay = lunarHourDay.getLunarDay().getDay();
        int lunarHour = lunarHourDay.getIndexInDay() + 1;

        log.info("lunarDay: {}", solarDay.getLunarDay());
        log.info("公历year={},month={},day={},hour={},minute={}", year, month, day, hour, minute);
        log.info("农历year={},month={},day={},hour={}", lunarYear, lunarMonth, lunarDay, lunarHour);

        return LunarDate.builder().year(lunarYear).month(lunarMonth).day(lunarDay).hour(lunarHour).lunarHour(lunarHourDay).build();
    }

}
